<?php
	class SystemAction extends BaseAction{
		public function index(){
			$sys = M('System');
			$data = $sys->field(true)
						->find();
			$this->assign('data',$data);
			$this->display();
		}
		
		//更新系统配置
		public function update(){
			$sys = D('System');
			if($sys->create()){
				if($sys->save()){
					$data = $sys->field(true)
								->find();
					$br = "\r\n";
					$tab = "\t";
					
					$profile = '<?php'.$br;
					$profile .= "if(!defined('THINK_PATH')) exit();".$br;
					$profile .='return array('.$br;
					$profile .= $tab."//系统配置文件".$br;
					$profile .= $tab."'WEB_NAME'".$tab.'=>'."'{$data['webname']}',//网站名称".$br;
					$profile .= $tab."'PAGESIZE'".$tab.'=>'."'{$data['page_size']}',//分页每页显示页数".$br;
					$profile .= $tab."'NAV_NUM'".$tab.'=>'."'{$data['nav_num']}',//分页每页显示页数".$br;
					$profile .= $tab."'ROTATION_NUM'".$tab.'=>'."'{$data['rotation_num']}',//首页轮播器图片显示数目".$br;
					$profile .= $tab."'ROTATION_TIME'".$tab.'=>'."'{$data['rotation_time']}',//首页轮播器图片播放速度".$br;
					$profile .= $tab."'TEXT_ADVER_NUM'".$tab.'=>'."'{$data['text_adver_num']}',//文字广告显示数目".$br;
					$profile .= $tab."'HEADER_ADVER_NUM'".$tab.'=>'."'{$data['header_adver_num']}',//头部图片广告显示数目".$br;
					$profile .= $tab."'SIDERBAR_ADVER_NUM'".$tab.'=>'."'{$data['siderbar_adver_num']}',//侧边栏图片广告显示数目".$br;
					$profile .= ');'.$br;
					$profile .= '?>'.$br;
					if (!file_put_contents('./sys_config.php', $profile)) {
						$this->error('更新系统配置失败！');
					}else{
						$this->success('更新系统配置成功！');
					}
				}else{
					$this->error('更新配置失败或配置没有改变！');
				}
			}else{
				$this->error($sys->getError());
			}
		}
	}
?>